package com.passer.webcrawler.config;

import com.amihaiemil.eoyaml.YamlMapping;
import com.passer.toolbox.common.core.util.YamlUtils;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * <p>配置类</p>
 * <p>创建时间：2023/5/9</p>
 *
 * @author hj
 */
@Slf4j
public class WebCrawlerConfig {
    @Getter
    private static String tempFolderName;
    @Getter
    private static String tempFolderParent;
    @Getter
    private static String tempFolderPath;
    @Getter
    private static int threadNum;

    public static void init() {
        YamlMapping webCrawlerYaml;
        try {
            webCrawlerYaml = YamlUtils.readYamlFile("/webCrawler.yaml");
        } catch (IOException e) {
            log.error("读取配置失败：{}", e.getMessage());
            return;
        }

        tempFolderName = webCrawlerYaml.string("temp-folder-name");
        tempFolderParent = webCrawlerYaml.string("temp-folder-parent");
        tempFolderPath = webCrawlerYaml.foldedBlockScalar("temp-folder-path");
        int threadNumYaml = webCrawlerYaml.integer("thread-num");
        if (threadNumYaml == -1) {
            threadNum = Runtime.getRuntime().availableProcessors();
        }
    }

}
